

using System;
using System.Collections.Generic;
using System.Text;

using SD.LLBLGen.Pro.ORMSupportClasses;
using DatabaseAdapter;
using DatabaseGeneric;
using DatabaseGeneric.FactoryClasses;
using DatabaseGeneric.EntityClasses;
using DatabaseGeneric.RelationClasses;
using DatabaseGeneric.HelperClasses;

namespace Services
{
    public class SanPhamGotChe : Interfaces.ISanPhamGotChe
    {
        public EntityCollection<SanPhamGotCheEntity> FetchCollection()
        {
            EntityCollection<SanPhamGotCheEntity> collectionSanPhamGotChe = new EntityCollection<SanPhamGotCheEntity>();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(collectionSanPhamGotChe, null);
            }
            return collectionSanPhamGotChe;
        }

        public EntityCollection<SanPhamGotCheEntity> FetchCollection(ChungLoaiSanPhamEntity currentEntityChungLoaiSanPham)
        {
            EntityCollection<SanPhamGotCheEntity> collectionSanPhamGotChe = new EntityCollection<SanPhamGotCheEntity>();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(collectionSanPhamGotChe, new RelationPredicateBucket(SanPhamGotCheFields.MaChungLoaiSanPham == currentEntityChungLoaiSanPham.MaChungLoaiSanPham));
            }
            return collectionSanPhamGotChe;
        }

        //public EntityCollection<SanPhamGotCheEntity> FetchCollection(string criteria, int option)
        //{
        //    EntityCollection<SanPhamGotCheEntity> collectionSanPhamGotChe = new EntityCollection<SanPhamGotCheEntity>();
        //    using (DataAccessAdapter adapter = new DataAccessAdapter())
        //    {
        //        switch (option)
        //        {
        //            case 1:
        //                adapter.FetchEntityCollection(collectionSanPhamGotChe, new RelationPredicateBucket(SanPhamGotCheFields.LoaiSanPhamGotChe == criteria));
        //                break;
        //        }
        //    }
        //    return collectionSanPhamGotChe;
        //}

        public SanPhamGotCheEntity FetchEntity(SanPhamGotCheEntity currentEntitySanPhamGotChe)
        {
            SanPhamGotCheEntity entitySanPhamGotChe = new SanPhamGotCheEntity(currentEntitySanPhamGotChe.MaSanPham);
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntity(entitySanPhamGotChe);
            }
            return entitySanPhamGotChe;
        }

        public int SaveCollection(EntityCollection<SanPhamGotCheEntity> currentCollectionSanPhamGotChe)
        {
            int cntSave = 0;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                cntSave = adapter.SaveEntityCollection(currentCollectionSanPhamGotChe);
            }
            return cntSave;
        }

        public bool SaveEntity(SanPhamGotCheEntity currentEntitySanPhamGotChe)
        {
            bool isSave = false;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                isSave = adapter.SaveEntity(currentEntitySanPhamGotChe);
            }
            return isSave;
        }

        public int DeleteCollection(EntityCollection<SanPhamGotCheEntity> currentCollectionSanPhamGotChe)
        {
            int cntDelete = 0;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.DeleteEntityCollection(currentCollectionSanPhamGotChe);
            }
            return cntDelete;
        }

        public bool DeleteEntity(SanPhamGotCheEntity currentEntitySanPhamGotChe)
        {
            bool isDelete = false;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                isDelete = adapter.DeleteEntity(currentEntitySanPhamGotChe);
            }
            return isDelete;
        }

        public System.Data.DataTable Report(ChungLoaiSanPhamEntity currentEntityChungLoaiSanPham)
        {
            System.Data.DataTable dtSanPhamGotChe = new System.Data.DataTable();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                dtSanPhamGotChe = RetrievalProcedures.SanPhamGotCheByChungLoaiSanPhamPro(currentEntityChungLoaiSanPham.MaChungLoaiSanPham, adapter);
            }
            return dtSanPhamGotChe;
        }
    }
}

